package com.joker.aigc.oj.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.joker.aigc.domain.entity.R;
import com.joker.aigc.oj.domain.entity.RecruitApply;
import com.joker.aigc.oj.service.RecruitApplyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Validated
@Slf4j
@RestController
@RequestMapping("/recruitApply")
@Tag(description = "招聘申请查询接口",name = "RecruitApplyController")
public class RecruitApplyController {

    @Autowired
    RecruitApplyService recruitApplyService;

    @Operation(summary = "根据用户，来获取用户信息")
    @RequestMapping(value = "/selectAllByUser", method = RequestMethod.POST)
    public R<IPage<RecruitApply>> selectAllByUser(@NotNull(message = "页数不能为空") @RequestParam("current") Integer current) {
        IPage<RecruitApply> recruitApplicationIPage = recruitApplyService.selectAllRecruitApplicationByUser(current);

        if (!recruitApplicationIPage.getRecords().isEmpty()) {
            return R.ok(recruitApplicationIPage);
        } else {
            return R.error(400,"对不起现在没有任何招聘要求");
        }
    }

    @Operation(summary = "管理员查询所有申请订单")
    @RequestMapping(value = "/selectAllByAdmin", method = RequestMethod.POST)
    public R<IPage<RecruitApply>> selectAllByAdmin(@NotNull(message = "页数不能为空") @RequestParam("current") Integer current) {
        IPage<RecruitApply> recruitApplicationIPage = recruitApplyService.selectAllRecruitApplicationByAdmin(current);
        if (!recruitApplicationIPage.getRecords().isEmpty()) {
            return R.ok(recruitApplicationIPage);
        } else {
            return R.error(201,"对不起现在没有任何招聘要求");
        }
    }


    @Operation(summary = "添加人员需求")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public R<String> addRecruitApply(@Valid @RequestBody RecruitApply recruitApply) {

        log.info(recruitApply.toString());
        Integer result = recruitApplyService.addRecruitApplication(recruitApply);

        if (result > 0) {
            return R.ok("添加成功");
        } else {
            return R.error(201,"添加失败");
        }
    }


}
